package com.gec.it.web;


import com.gec.it.entity.Jobs;
import com.gec.it.service.JobsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wf
 * @since 2022-01-05
 */
@Controller
//@RequestMapping("/jobs")
public class JobsController {
    @Autowired
    private JobsService service = null;


    @GetMapping("/job_list")
    public String job_list(Model m){
        List<Jobs> jobs = service.list2();
        m.addAttribute("list",jobs);
        return "job_list";
    }


    @GetMapping("/job_add")
    public String job_add(){
        return "job_add";
    }

    @PostMapping("/job_add")
    public String job_add(Jobs jobs){
        service.save(jobs);
        return "redirect:job_list";
    }

    @GetMapping("/job_edit")
    public String job_edit(int id, Model m){
        Jobs byId2 = service.getById2(id);
        m.addAttribute("list",byId2);
        return "job_edit";
    }

    @PostMapping("/job_edit")
    public String job_edit(int id ,Jobs jobs){
        jobs.setJobId(id);
        service.updateById(jobs);
        return "redirect:job_list";
    }

    @GetMapping("/job_del")
    public String job_del(int id){
        service.removeById(id);
        return "redirect:job_list";
    }
}
